﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace LiteQuery.Controls
{
    public partial class FieldPanel : UserControl
    {
        public event EventHandler OnValueChanged;

        Entities.Field field;
        public Entities.Field FieldInfo
        {
            get
            {
                if (field == null)
                    field = new Entities.Field();
                field.Value = txtValue.Text;
                return field;
            }
            set { field = value; }
        }

        public string Caption
        {
            get { return lblCaption.Text; }
            set
            {
                if (lblCaption.InvokeRequired)
                    lblCaption.Invoke(new Action(() => lblCaption.Text = value));
                else
                    lblCaption.Text = value;
            }
        }

        public FieldPanel()
        {
            InitializeComponent();
        }

        public FieldPanel(Entities.Field fi)
        {
            InitializeComponent();
            this.FieldInfo = fi;
            this.Caption = fi.Caption;
        }

        private void txtValue_TextChanged(object sender, EventArgs e)
        {
            field.Value = txtValue.Text;
            if (OnValueChanged != null)
                OnValueChanged(this, null);
        }
    }
}
